<?php
/**
 * Created by PhpStorm.
 * User: Mmx
 * Date: 2021/4/18
 * Time: 14:23
 */

namespace app\backend\controller\v1;


class Music extends BaseController
{
    public function music()
    {
        $files = $_FILES;
        if(!$files){
            return errMsg(400,'请上传音频！');
        }
        $imageArr = Array();
        foreach ($files as $file) {
            $imageName = $file['name'];
            //后缀名
            $ext = strtolower(substr(strrchr($imageName,'.'),1));
            //保存文件名
            $fileName = uniqid();
            $tmp = $file['tmp_name'];
            //保存 = 路径 + 文件名 + 后缀名
            $imageSavePath = '../public/uploads/music/'.$fileName.'.'.$ext;
            $info = move_uploaded_file($tmp, $imageSavePath);

            if ($info) {
                $path = "uploads/music/".$fileName.'.'.$ext;
                array_push($imageArr, $path);
            }else{
                return errMsg(400,'上传失败！');
            }
        }
        //最终生成的字符串路径
        $imagePathStr = implode(',', $imageArr);
        return sucessMsg(200,'上传成功！',$imagePathStr);
    }
}